
var userId = 0;

function getUserId(id){
	userId = id;
}

$(function(){
	
	var keywords = '';
	var flag = 0;
	
	$('#search-btn').click(function(){
		
		var keyword = $('#keyword').val();
		keywords = keyword;
		showRes(3,keywords);
		
		flag = 0;
		
	});
	
	
	
	function searchShow(pageNumber,showNumber,keyWord){
		
		$.getJSON('../KeyWordsSearch',{
			pageNumber:pageNumber,
			showNumber:showNumber,
			keyWord:keyWord
		},function(data,status){
			if(status){
				
				$('.product-one').empty();
				
				console.log('user-id:'+userId);
				
				for(var i=0;i<data.length;i++){
					
					//等待sql语句的完善
					
					$('.product-one').append('<div class="col-md-4 product-left single-left">'+
							'<div class="p-one simpleCart_shelfItem"><a href="dog.jsp?id='+data[i].id+'">'+
							'<img src="../images/'+data[i].image1+'" alt="" width="200px"height="150px"/>'+
							'<div class="mask mask1"><span>快速查看</span></div></a><h4> '+data[i].name+
							'</h4><p><a class="item_add" href="#" onclick="cart_add('+data[i].id+',1,1,  '+userId+'  ,'+data[i].specialPrice+' )">'+
							'<span style="display: none"> '+data[i].id+' </span><i></i> <span class=" item_price">￥ '+data[i].nowPrice+' </span>'+
							'</a></p></div></div>');
					
				}
				
			}
		});
		
	}
	
	
	
	//执行一次即可
	function showRes(showNumber,keyWord){
		
		
		$('.product-one').empty();
		$('.page-show').empty();
		
		$('.page-show').append('<div id="example" style="text-align: center"><ul id="pageLimit"></ul></div>');
		
		
		
		var allPages = 1;
		
		$.getJSON('../KeyWordsSearch',{
			showNumber:showNumber,
			keyWord:keyWord,
			flag:1
			},function(data,status){
			if(status){
				allPages = data[0].pages;
			}
			
		});
		
		searchShow(1,3,keywords);
		
		$('#pageLimit').bootstrapPaginator({
			currentPage : 1,
			totalPages : allPages,
			size : "normal",
			bootstrapMajorVersion : 3,
			alignment : "right",
			numberOfPages : 5,
			itemTexts : function(type, page, current) {
				switch (type) {
				case "first":
					return "首页";
				case "prev":
					return "上一页";
				case "next":
					return "下一页";
				case "last":
					return "末页";
				case "page":
					return page;
				}
			},

			onPageClicked : function(event, originalEvent, type, page) {
				console.log("1:" + page);
				
				searchShow(page,3,keywords);
				
			},
		});
		
	}
	
})








